 package tools.packet;



import client.MapleCharacter;
import handling.opcode.PartyOpcode;
import handling.opcode.SendPacketOpcode;
import handling.world.PartyOperation;
import handling.world.WorldPartyService;
import handling.world.party.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import tools.data.output.MaplePacketLittleEndianWriter;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;























 public class PartyPacket
 {
/*  28 */   private static final Logger log = LogManager.getLogger(PartyPacket.class);


   private static final int 搜索队伍 = 108;


   public static byte[] partyCreated(MapleParty party) {
/*  35 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/*  37 */     mplew.writeShort(SendPacketOpcode.PARTY_OPERATION.getValue());
/*  38 */     mplew.write(PartyOpcode.PartyRes_CreateNewParty_Done.getValue());
/*  39 */     mplew.writeInt(party.getPartyId());
/*  40 */     mplew.writeInt(999999999);
/*  41 */     mplew.writeInt(999999999);
/*  42 */     mplew.writeZeroBytes(9);
/*  43 */     mplew.write(party.isHidden() ? 0 : 1);
/*  44 */     mplew.write(0);
/*  45 */     mplew.writeMapleAsciiString(party.getName());

/*  47 */     return mplew.getPacket();
   }




   public static byte[] partyInvite(MapleCharacter from) {
/*  54 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/*  55 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/*  57 */     mplew.writeShort(SendPacketOpcode.PARTY_OPERATION.getValue());
/*  58 */     mplew.write(PartyOpcode.PartyReq_InviteParty.getValue());
/*  59 */     mplew.writeInt(from.getId());
/*  60 */     mplew.writeMapleAsciiString(from.getName());
/*  61 */     mplew.writeInt(from.getLevel());
/*  62 */     from.writeJobData(mplew);
/*  63 */     mplew.writeInt(0);
/*  64 */     mplew.writeShort(0);

/*  66 */     return mplew.getPacket();
   }




   public static byte[] partyRequestInvite(MapleCharacter from) {
/*  73 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/*  74 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/*  76 */     mplew.writeShort(SendPacketOpcode.PARTY_OPERATION.getValue());
/*  77 */     mplew.write(PartyOpcode.PartyReq_ApplyParty.getValue());
/*  78 */     mplew.writeInt(from.getId());
/*  79 */     mplew.writeMapleAsciiString(from.getName());
/*  80 */     mplew.writeInt(from.getLevel());
/*  81 */     from.writeJobData(mplew);
/*  82 */     mplew.writeInt(0);

/*  84 */     return mplew.getPacket();
   }

   public static byte[] partyStatusMessage(int message) {
/*  88 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/*  89 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();












/* 102 */     mplew.writeShort(SendPacketOpcode.PARTY_OPERATION.getValue());
/* 103 */     mplew.write(message);

/* 105 */     return mplew.getPacket();
   }




   public static byte[] partyStatusMessage(int message, String charName) {
/* 112 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 113 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 115 */     mplew.writeShort(SendPacketOpcode.PARTY_OPERATION.getValue());
/* 116 */     mplew.write(message);
/* 117 */     mplew.writeMapleAsciiString(charName);

/* 119 */     return mplew.getPacket();
   }

   private static void addPartyStatus(int forchannel, MapleParty party, MaplePacketLittleEndianWriter lew, boolean leaving) {
/* 123 */     addPartyStatus(forchannel, party, lew, leaving, false);
   }

   private static void addPartyStatus(int forchannel, MapleParty party, MaplePacketLittleEndianWriter lew, boolean leaving, boolean exped) {
     List<MaplePartyCharacter> partymembers;
/* 128 */     if (party == null) {
/* 129 */       partymembers = new ArrayList<>();
     } else {
/* 131 */       partymembers = new ArrayList<>(party.getMembers());
     }
/* 133 */     while (partymembers.size() < 6) {
/* 134 */       partymembers.add(new MaplePartyCharacter());
     }
/* 136 */     for (MaplePartyCharacter partychar : partymembers) {
/* 137 */       lew.writeInt(partychar.getId());
     }
/* 139 */     for (MaplePartyCharacter partychar : partymembers) {
/* 140 */       lew.writeAsciiString(partychar.getName(), 13);
     }
/* 142 */     for (MaplePartyCharacter partychar : partymembers) {
/* 143 */       lew.writeInt(partychar.getJobId());
     }
/* 145 */     for (MaplePartyCharacter partychar : partymembers) {
/* 146 */       lew.writeInt(0);
     }
/* 148 */     for (MaplePartyCharacter partychar : partymembers) {
/* 149 */       lew.writeInt(partychar.getLevel());
     }
/* 151 */     for (MaplePartyCharacter partychar : partymembers) {
/* 152 */       if (partychar.isOnline()) {
/* 153 */         lew.writeInt(partychar.getChannel() - 1); continue;
       }
/* 155 */       lew.writeInt(-2);
     }

/* 158 */     for (MaplePartyCharacter partychar : partymembers) {
/* 159 */       lew.writeInt(0);
     }
/* 161 */     for (MaplePartyCharacter partychar : partymembers) {
/* 162 */       lew.writeInt(0);
     }
/* 164 */     lew.writeInt((party == null) ? 0 : party.getLeader().getId());
/* 165 */     if (exped) {
       return;
     }
/* 168 */     for (MaplePartyCharacter partychar : partymembers) {
/* 169 */       if (partychar.getChannel() == forchannel) {
/* 170 */         lew.writeInt(partychar.getMapid()); continue;
       }
/* 172 */       lew.writeInt(0);
     }

/* 175 */     for (MaplePartyCharacter partychar : partymembers) {
/* 176 */       if (partychar.getChannel() == forchannel && !leaving) {
/* 177 */         lew.writeInt(partychar.getDoorTown());
/* 178 */         lew.writeInt(partychar.getDoorTarget());
/* 179 */         lew.writeInt(partychar.getDoorSkill());
/* 180 */         lew.writeInt((partychar.getDoorPosition()).x);
/* 181 */         lew.writeInt((partychar.getDoorPosition()).y); continue;
       }
/* 183 */       lew.writeInt(leaving ? 999999999 : 0);
/* 184 */       lew.writeInt(leaving ? 999999999 : 0);
/* 185 */       lew.writeInt(0);
/* 186 */       lew.writeInt(leaving ? -1 : 0);
/* 187 */       lew.writeInt(leaving ? -1 : 0);
     }

/* 190 */     lew.writeShort((party != null && party.isHidden()) ? 0 : 1);
/* 191 */     String[] arrstring = new String[4];
/* 192 */     arrstring[0] = (party != null) ? party.getName() : null;
/* 193 */     arrstring[1] = null;
/* 194 */     arrstring[2] = null;
/* 195 */     arrstring[3] = null;
/* 196 */     lew.writeMapleAsciiString(arrstring);
/* 197 */     lew.writeInt(0);
/* 198 */     for (int i = 0; i < 2; i++) {
/* 199 */       lew.write(0);
/* 200 */       lew.write(0);
/* 201 */       lew.writeBool(false);
/* 202 */       lew.write(2);
/* 203 */       lew.writeInt(0);
/* 204 */       lew.writeLong(0L);
/* 205 */       lew.writeInt(0);
/* 206 */       lew.writeInt(0);
     }
   }

   public static byte[] updateParty(int forChannel, MapleParty party, PartyOperation op, MaplePartyCharacter target) {
/* 211 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 212 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 214 */     mplew.writeShort(SendPacketOpcode.PARTY_OPERATION.getValue());
/* 215 */     switch (op) {
       case 解散队伍:
       case 驱逐成员:
       case 离开队伍:
/* 219 */         mplew.write(PartyOpcode.PartyRes_WithdrawParty_Done.getValue());
/* 220 */         mplew.writeInt(party.getPartyId());
/* 221 */         mplew.writeInt(target.getId());
/* 222 */         mplew.write((op == PartyOperation.解散队伍) ? 0 : 1);
/* 223 */         if (op == PartyOperation.解散队伍) {
/* 224 */           mplew.writeInt(target.getId()); break;
         }
/* 226 */         mplew.write((op == PartyOperation.驱逐成员) ? 1 : 0);
/* 227 */         mplew.writeMapleAsciiString(target.getName());
/* 228 */         addPartyStatus(forChannel, party, mplew, (op == PartyOperation.离开队伍));
         break;

       case 加入队伍:
/* 232 */         mplew.write(PartyOpcode.PartyRes_JoinParty_Done.getValue());
/* 233 */         mplew.writeInt(party.getPartyId());
/* 234 */         mplew.writeMapleAsciiString(target.getName());
/* 235 */         mplew.writeZeroBytes(5);

/* 237 */         addPartyStatus(forChannel, party, mplew, false);
         break;

       case 更新队伍:
       case LOG_ONOFF:
/* 242 */         mplew.write((op == PartyOperation.LOG_ONOFF) ? PartyOpcode.PartyRes_UserMigration.getValue() : ((party != null) ? PartyOpcode.PartyRes_LoadParty_Done.getValue() : PartyOpcode.PartyRes_LoadParty_NoParty.getValue()));
/* 243 */         mplew.writeInt(party.getPartyId());

/* 245 */         addPartyStatus(forChannel, party, mplew, (op == PartyOperation.LOG_ONOFF));
         break;
       case 改变队长:
       case CHANGE_LEADER_DC:
/* 249 */         mplew.write(PartyOpcode.PartyRes_ChangePartyBoss_Done.getValue());
/* 250 */         mplew.writeInt(target.getId());
/* 251 */         mplew.write((op == PartyOperation.CHANGE_LEADER_DC) ? 1 : 0);
         break;
       case 队伍设置:
/* 254 */         mplew.write(PartyOpcode.PartyRes_PartySettingDone.getValue());
/* 255 */         mplew.write(party.isHidden() ? 0 : 1);
/* 256 */         mplew.writeMapleAsciiString(party.getName(), 30);
         break;
     }
/* 259 */     return mplew.getPacket();
   }




   public static byte[] partyPortal(int townId, int targetId, int skillId, Point position, boolean animation) {
/* 266 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 267 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 269 */     mplew.writeShort(SendPacketOpcode.PARTY_OPERATION.getValue());
/* 270 */     mplew.write(PartyOpcode.PartyInfo_TownPortalChanged.getValue());
/* 271 */     mplew.write(animation ? 0 : 1);
/* 272 */     mplew.writeInt(townId);
/* 273 */     mplew.writeInt(targetId);
/* 274 */     mplew.writeInt(skillId);
/* 275 */     mplew.writePos(position);

/* 277 */     return mplew.getPacket();
   }




   public static byte[] updatePartyMemberHP(int chrId, int curhp, int maxhp) {
/* 284 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 286 */     mplew.writeShort(SendPacketOpcode.UPDATE_PARTYMEMBER_HP.getValue());
/* 287 */     mplew.writeInt(chrId);
/* 288 */     mplew.writeInt(curhp);
/* 289 */     mplew.writeInt(maxhp);

/* 291 */     return mplew.getPacket();
   }





   public static byte[] getPartyListing(PartySearchType pst) {
/* 299 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 300 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 301 */     mplew.writeShort(SendPacketOpcode.PARTY_OPERATION.getValue());
/* 302 */     mplew.write(108);
/* 303 */     mplew.writeInt(pst.id);
/* 304 */     List<PartySearch> parties = WorldPartyService.getInstance().searchParty(pst);
/* 305 */     mplew.writeInt(parties.size());
/* 306 */     for (PartySearch party : parties) {
/* 307 */       if (pst.exped) {
/* 308 */         MapleExpedition me = WorldPartyService.getInstance().getExped(party.getId());
/* 309 */         mplew.writeInt(party.getId());
/* 310 */         mplew.writeAsciiString(party.getName(), 37);

/* 312 */         mplew.writeInt(pst.id);
/* 313 */         mplew.writeInt(0);
/* 314 */         for (int i = 0; i < 5; i++) {
/* 315 */           if (i < me.getParties().size()) {
/* 316 */             MapleParty part = WorldPartyService.getInstance().getParty(((Integer)me.getParties().get(i)).intValue());
/* 317 */             if (part != null) {
/* 318 */               addPartyStatus(-1, part, mplew, false, true);
             } else {
/* 320 */               mplew.writeZeroBytes(226);
             }
           } else {
/* 323 */             mplew.writeZeroBytes(226);
           }
         }  continue;
       }
/* 327 */       mplew.writeInt(party.getId());
/* 328 */       mplew.writeAsciiString(party.getName(), 37);
/* 329 */       addPartyStatus(-1, WorldPartyService.getInstance().getParty(party.getId()), mplew, false, true);
     }


/* 333 */     return mplew.getPacket();
   }





   public static byte[] partyListingAdded(PartySearch ps) {
/* 341 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 342 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 343 */     mplew.writeShort(SendPacketOpcode.PARTY_OPERATION.getValue());
/* 344 */     mplew.write(106);
/* 345 */     mplew.writeInt((ps.getType()).id);
/* 346 */     if ((ps.getType()).exped) {
/* 347 */       MapleExpedition me = WorldPartyService.getInstance().getExped(ps.getId());

/* 349 */       mplew.writeInt(ps.getId());
/* 350 */       mplew.writeAsciiString(ps.getName(), 37);
/* 351 */       mplew.writeInt((ps.getType()).id);
/* 352 */       mplew.writeInt(0);
/* 353 */       for (int i = 0; i < 5; i++) {
/* 354 */         if (i < me.getParties().size()) {
/* 355 */           MapleParty party = WorldPartyService.getInstance().getParty(((Integer)me.getParties().get(i)).intValue());
/* 356 */           if (party != null) {
/* 357 */             addPartyStatus(-1, party, mplew, false, true);
           } else {
/* 359 */             mplew.writeZeroBytes(226);
           }
         } else {
/* 362 */           mplew.writeZeroBytes(226);
         }
       }
     } else {
/* 366 */       mplew.writeInt(ps.getId());
/* 367 */       mplew.writeAsciiString(ps.getName(), 37);
/* 368 */       addPartyStatus(-1, WorldPartyService.getInstance().getParty(ps.getId()), mplew, false, true);
     }

/* 371 */     return mplew.getPacket();
   }





   public static byte[] removePartySearch(PartySearch ps) {
/* 379 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 380 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 381 */     mplew.writeShort(SendPacketOpcode.PARTY_OPERATION.getValue());
/* 382 */     mplew.write(107);
/* 383 */     mplew.writeInt((ps.getType()).id);
/* 384 */     mplew.writeInt(ps.getId());
/* 385 */     mplew.writeInt(2);

/* 387 */     return mplew.getPacket();
   }





   public static byte[] expeditionStatus(MapleExpedition me, boolean created) {
/* 395 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 396 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 397 */     mplew.writeShort(SendPacketOpcode.EXPEDITION_OPERATION.getValue());
/* 398 */     mplew.write(created ? 86 : 88);
/* 399 */     mplew.writeInt((me.getType()).exped);
/* 400 */     mplew.writeInt(0);
/* 401 */     for (int i = 0; i < 5; i++) {
/* 402 */       if (i < me.getParties().size()) {
/* 403 */         MapleParty party = WorldPartyService.getInstance().getParty(((Integer)me.getParties().get(i)).intValue());
/* 404 */         if (party != null) {
/* 405 */           addPartyStatus(-1, party, mplew, false, true);
         } else {
/* 407 */           mplew.writeZeroBytes(226);
         }
       } else {
/* 410 */         mplew.writeZeroBytes(226);
       }
     }

/* 414 */     return mplew.getPacket();
   }





   public static byte[] expeditionInviteMessage(int code, String name) {
/* 422 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 423 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 425 */     mplew.writeShort(SendPacketOpcode.EXPEDITION_OPERATION.getValue());
/* 426 */     mplew.write(100);










/* 437 */     mplew.writeInt(code);
/* 438 */     mplew.writeMapleAsciiString(name);

/* 440 */     return mplew.getPacket();
   }





   public static byte[] expeditionJoined(String name) {
/* 448 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 449 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 450 */     mplew.writeShort(SendPacketOpcode.EXPEDITION_OPERATION.getValue());
/* 451 */     mplew.write(87);
/* 452 */     mplew.writeMapleAsciiString(name);

/* 454 */     return mplew.getPacket();
   }





   public static byte[] expeditionLeft(boolean left, String name) {
/* 462 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 463 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 464 */     mplew.writeShort(SendPacketOpcode.EXPEDITION_OPERATION.getValue());




/* 469 */     mplew.write(left ? 91 : 93);
/* 470 */     mplew.writeMapleAsciiString(name);

/* 472 */     return mplew.getPacket();
   }





   public static byte[] expeditionMessage(boolean disbanded) {
/* 480 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 481 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 482 */     mplew.writeShort(SendPacketOpcode.EXPEDITION_OPERATION.getValue());




/* 487 */     mplew.write(disbanded ? 95 : 94);

/* 489 */     return mplew.getPacket();
   }





   public static byte[] expeditionLeaderChanged(int newLeader) {
/* 497 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 498 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 499 */     mplew.writeShort(SendPacketOpcode.EXPEDITION_OPERATION.getValue());
/* 500 */     mplew.write(96);
/* 501 */     mplew.writeInt(newLeader);

/* 503 */     return mplew.getPacket();
   }






   public static byte[] expeditionUpdate(int partyIndex, MapleParty party) {
/* 512 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 513 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 514 */     mplew.writeShort(SendPacketOpcode.EXPEDITION_OPERATION.getValue());
/* 515 */     mplew.write(97);
/* 516 */     mplew.writeInt(0);
/* 517 */     mplew.writeInt(partyIndex);
/* 518 */     if (party == null) {
/* 519 */       mplew.writeZeroBytes(250);
     } else {
/* 521 */       addPartyStatus(-1, party, mplew, false, true);
     }

/* 524 */     return mplew.getPacket();
   }






   public static byte[] expeditionInvite(MapleCharacter from, int exped) {
/* 533 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 534 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 536 */     mplew.writeShort(SendPacketOpcode.EXPEDITION_OPERATION.getValue());
/* 537 */     mplew.write(99);
/* 538 */     mplew.writeInt(from.getLevel());
/* 539 */     from.writeJobData(mplew);
/* 540 */     mplew.writeInt(0);
/* 541 */     mplew.writeMapleAsciiString(from.getName());
/* 542 */     mplew.writeInt(exped);

/* 544 */     return mplew.getPacket();
   }




   public static byte[] showMemberSearch(List<MapleCharacter> players) {
/* 551 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 552 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 553 */     mplew.writeShort(SendPacketOpcode.MEMBER_SEARCH.getValue());
/* 554 */     mplew.write(players.size());
/* 555 */     for (MapleCharacter chr : players) {
/* 556 */       mplew.writeInt(chr.getId());
/* 557 */       mplew.writeMapleAsciiString(chr.getName());
/* 558 */       chr.writeJobData(mplew);
/* 559 */       mplew.writeInt(chr.getLevel());
     }

/* 562 */     return mplew.getPacket();
   }




   public static byte[] showPartySearch(List<MapleParty> partylist) {
/* 569 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 570 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 571 */     mplew.writeShort(SendPacketOpcode.PARTY_SEARCH.getValue());
/* 572 */     mplew.write(partylist.size());
/* 573 */     for (MapleParty party : partylist) {
/* 574 */       mplew.writeInt(party.getPartyId());
/* 575 */       mplew.writeMapleAsciiString(party.getLeader().getName());
/* 576 */       mplew.write(party.getLeader().getLevel());
/* 577 */       mplew.write(party.getLeader().isOnline() ? 1 : 0);
/* 578 */       mplew.writeMapleAsciiString(party.getName());
/* 579 */       mplew.write(party.getMembers().size());
/* 580 */       for (MaplePartyCharacter partyChr : party.getMembers()) {
/* 581 */         mplew.writeInt(partyChr.getId());
/* 582 */         mplew.writeMapleAsciiString(partyChr.getName());
/* 583 */         mplew.writeInt(partyChr.getJobId());
/* 584 */         mplew.write(partyChr.getLevel());
/* 585 */         mplew.write(partyChr.isOnline() ? 1 : 0);
/* 586 */         mplew.write(-1);
       }
     }

/* 590 */     return mplew.getPacket();
   }
 }


/* Location:              C:\PGX\Server.jar!\tools\packet\PartyPacket.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */